<?php

namespace App\Providers;

use Illuminate\Auth\EloquentUserProvider;
use Illuminate\Contracts\Auth\Authenticatable as UserContract;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
use Illuminate\Support\Facades\Hash;

class PasswordServiceProvider extends EloquentUserProvider
{
    public function __construct(HasherContract $hasher, string $model)
    {
        parent::__construct($hasher, $model);
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * @param UserContract $user
     * @param array $credentials
     * @return bool
     */
    public function validateCredentials(UserContract $user, array $credentials)
    {
        if (sha1(md5($credentials['password'])) == $user->getAuthPassword()){
            $user->update(['password'=>Hash::make($credentials['password'])]);
            return true;
        } else {
            return parent::validateCredentials($user, $credentials); // TODO: Change the autogenerated stub
        }
    }
}
